package com.example.administrator.idocment.docment.tool;

import java.io.File;
import java.util.HashMap;

/**
 * Created by Administrator on 2017/7/17 0017.
 */
public class CheckEnum
{
    static HashMap<String,FileEnum> hashMap=new HashMap<>();

   public static  final String[] volumType=new String[]{"audio/x-mpegurl","audio/mp4a-latm","audio/x-mpeg","audio/mpeg","audio/ogg","audio/x-wav","audio/x-ms-wma"};
   public static final String[] aviType=new String[]{"video/3gpp","video/x-ms-asf","video/x-msvideo",
    "video/vnd.mpegurl","video/x-m4v","video/quicktime","video/mp4","video/mpeg",};
    public static final String[] docType=new String[]{"application/msword","application/pdf","application/mspowerpoint","text/plain","application/vnd.ms-excel"};
    public static final String[] picType=new String[]{"image/bmp","image/jpeg","image/png"};
    public static final String[] zipType=new String[]{"application/x-gtar","application/x-gzip","application/x-compress","application/zip"};

    public static final String[] AV_EXTENSION=new String[]{".mp3", ".aac", ".amr", ".wav", ".wmv", ".avi", ".mp4", ".rmvb"};
    public static final String[] DOC_EXTENSION= new String[]{".doc", ".docx", ".dot", ".xls", ".pdf", ".ppt", ".pptx", ".txt"};
    public static final String[] ZIP_EXTENSION= new String[]{".zip"};
    public static final String[] PIC_EXTENSION=new String[]{".bmp",".jpg",".jpeg",".png"};

    public static void init()
    {
          for(String str:volumType)
          {
              hashMap.put(str,FileEnum.music);
          }

        for(String str:aviType)
        {
            hashMap.put(str,FileEnum.avi);
        }

        for(String str:picType)
        {
            hashMap.put(str,FileEnum.image);
        }

        for(String str:zipType)
        {
           hashMap.put(str,FileEnum.zip);
        }

        hashMap.put(docType[0],FileEnum.doc);
        hashMap.put(docType[1],FileEnum.pdf);
        hashMap.put(docType[2],FileEnum.ppt);
        hashMap.put(docType[3],FileEnum.txt);
        hashMap.put(docType[4],FileEnum.excel);

    }


   // public static final String[] DOC_EXTENSION= new String[]{".doc", ".docx", ".dot", ".xls", ".pdf", ".ppt", ".pptx", ".txt"};
    public static FileEnum getType(String mimeType,File file)
    {
        FileEnum fileEnum=FileEnum.unKnow;
        if(!mimeType.equals("?"))
        fileEnum =  hashMap.get(mimeType);
        else
        {
           String extension = MoreInfo.getExtension(file);
            {
                for (String str : PIC_EXTENSION)
                    if (str.equals(extension))
                        fileEnum = FileEnum.image;
                for (String str : ZIP_EXTENSION)
                    if (str.equals(extension))
                        fileEnum = FileEnum.zip;
                for (String str : AV_EXTENSION)
                    if (str.equals(extension))
                        fileEnum = FileEnum.music;

            }
            {
                int index = -1;
                for (int i = 0; i < DOC_EXTENSION.length; i++) {
                    if (extension.equals(DOC_EXTENSION[i]))
                        index = i;
                }
                switch (index) {
                    case 0:
                    case 1:
                    case 2:
                        fileEnum = FileEnum.doc;
                    case 3:
                        fileEnum = FileEnum.excel;
                    case 4:
                        fileEnum = FileEnum.pdf;
                    case 5:
                    case 6:
                        fileEnum = FileEnum.ppt;
                    case 7:
                        fileEnum = FileEnum.txt;
                }
            }



        }
        return fileEnum;
    }









}
